package com.bzframework.project.api.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.DefaultValue;
import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import org.hswebframework.web.api.crud.entity.RecordCreationEntity;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.crud.generator.Generators;

import javax.persistence.Column;
import javax.persistence.Table;
import java.sql.JDBCType;
import java.util.Map;

@Getter
@Setter
@Table(name = "open_api")
@EnableEntityEvent
public class OpenApiEntity extends GenericEntity<String> implements RecordCreationEntity {

    @Column(nullable = false)
    @Schema(description = "文件名称")
    private String name;

    @Column(nullable = false)
    @Schema(description = "文件类型")
    private String extension;

    @Column(nullable = false, updatable = false)
    @Schema(description = "文件大小")
    private Long length;

    @Column(nullable = false, updatable = false, length = 32)
    @Schema(description = "MD5哈希值")
    private String md5;

    @Column(nullable = false, updatable = false, length = 64)
    @Schema(description = "SHA-256哈希值")
    private String sha256;

    @Column(length = 512, updatable = false, nullable = false)
    @Schema(description = "存储地址")
    private String storagePath;

    @Column
    @JsonCodec
    @ColumnType(jdbcType = JDBCType.LONGVARCHAR, javaType = String.class)
    @Schema(description = "其他配置")
    private Map<String, Object> others;

    @Column(nullable = false, updatable = false)
    @DefaultValue(generator = Generators.CURRENT_TIME)
    @Schema(
            description = "创建时间(只读)"
            , accessMode = Schema.AccessMode.READ_ONLY
    )
    private Long createTime;

    @Column(length = 64, updatable = false)
    @Schema(
            description = "创建者ID(只读)"
            , accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorId;

}

